package com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.item;

import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.ClassReader;
import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.ConstantInfo;
import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.ConstantPool;

public class ConstantClassInfo implements ConstantInfo {

    public ConstantPool constantPool;
    public int nameIdx;

    public ConstantClassInfo(ConstantPool constantPool) {
         this.constantPool = constantPool;
    }

    @Override
    public void readInfo(ClassReader reader) {
//         this.nameIdx = reader.readUint16();
         this.nameIdx = reader.readU2();
    }

    @Override
    public void showInfo() {
        System.out.println("tag 是：" + this.tag() + ", class 或 interface的符号引用是: " + this.name());
    }

    public String name(){
        return this.constantPool.getUTF8(this.nameIdx);
    }

    @Override
    public int tag() {
        return this.CONSTANT_TAG_CLASS;
    }

}
